package org.cfx.basic.listener;

import org.cfx.auth.service.IAutoScanPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @author RTX 9090
 */
@Component
public class PermissionInitListener implements ServletContextListener {

    @Autowired
    private IAutoScanPermissionService autoScanPermissionService;

    @Value("${listener.isListener}")
    private Boolean isScanning;

    @Override
    public void contextInitialized(ServletContextEvent sce) {
        System.out.println("----------Tomcat启动---------");
//        System.out.println(isScanning);
        if (isScanning){
            autoScanPermissionService.scan();
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        System.out.println("----------Tomcat销毁---------");
    }
}
